import pandas
fujian2_df = pandas.read_csv('D:\ProgramFile2_OR\Python_study\mathorcup2024C\附件\附件2.csv',encoding = 'utf-8')
fujian2_df['日期'] = pandas.to_datetime(fujian2_df['日期'])
strSplit_num = [int(item[2:]) for item in fujian2_df['分拣中心']]
fujian2_df['asSort'] = strSplit_num
data_group = fujian2_df.sort_values(by = 'asSort').reset_index(drop = True)
data_fujian2 = data_group.groupby('asSort').apply(lambda x:x.sort_values(by = '日期')\
                                                  .reset_index(drop = True)).reset_index(drop = True)
data_fujian2 = data_fujian2.drop('asSort',axis = 1)
data_sorted = data_fujian2.groupby(by = ['分拣中心','日期']).apply(lambda x: x.sort_values(by = '小时')\
                                                             .reset_index(drop = True)).reset_index(drop = True)
data_sorted.to_csv(r"D:\ProgramFile2_OR\Python_study\mathorcup2024C\sortData_fujian2.csv",index = False,encoding = 'utf-8')


data_df = pandas.read_csv('D:\ProgramFile2_OR\Python_study\mathorcup2024C\sortData_fujian2.csv',encoding  ='utf-8')
print(data_df.iloc[30*24:50*24,:])
dataAsort = [int(item[2:]) for item in data_df['分拣中心']]
data_df['Asort'] = dataAsort
data_df = data_df.sort_values('Asort').reset_index(drop = True)
print(data_df.iloc[30*24:50*24,:])

data_df.to_csv(r"D:\ProgramFile2_OR\Python_study\mathorcup2024C\sortData_finall_fujian2.csv",index = False,encoding = 'utf-8')